{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 舵机驱动Nano模块API文档"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 目录\n",
    "- [初始化nano控制板对象](#初始化nano控制板对象)\n",
    "- [获取API版本](#获取API版本)\n",
    "- [设置Nano控制板CAN_ID\n",
    "](#设置Nano控制板CAN_ID\n",
    ")\n",
    "- [设置舵机位置](#设置舵机位置)\n",
    "- [设置PWM值](#设置PWM值)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 初始化nano控制板对象\n",
    "出厂ID： 0x21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from robodyno import Robot\n",
    "from robodyno.nodes import NanoBoardFactory\n",
    "robot = Robot()\n",
    "nano_board = robot.add_device('end_effector', NanoBoardFactory(), 0x21)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 获取API版本\n",
    "`get_api_ver(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "- timeout: 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "- API版本dict\n",
    "    - device_uuid: 设备uuid\n",
    "    - main_version: 主版本号\n",
    "    - sub_version: 副版本号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'device_uuid': 97, 'main_version': 0, 'sub_version': 3}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nano_board.get_api_ver(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置Nano控制板CAN_ID\n",
    "`set_node_id(node_id)`\n",
    "\n",
    "参数:\n",
    "- node_id: 新CAN_ID (0x01~0x3F)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "nano_board.set_node_id(0x21)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置舵机位置\n",
    "`set_servo_pos(servo_pos)`\n",
    "\n",
    "参数：\n",
    "- servo_pos: 舵机位置, (0 ~ 1) 舵机最小位置 ~ 舵机最大位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "nano_board.set_servo_pos(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置PWM值\n",
    "`set_pwm(pwm)`\n",
    "\n",
    "参数：\n",
    "- pwm: 占空比, (0 ~ 1) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "nano_board.set_pwm(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "767d51c1340bd893661ea55ea3124f6de3c7a262a8b4abca0554b478b1e2ff90"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
